@extends('layouts.admin-iframe-base')


@section('css')
    <style>
        .upload{position: relative; height: 40px;}
        .upload a{position: absolute; z-index: 0; width: 80px; text-align: center;}
        .upload input{width: 80px; opacity: 0; left: 0; top: 0; position: absolute; z-index: 1;}
    </style>
@stop

@section('content')
        <!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        用户管理
        <small>用户电站</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
        <li class="active">首页</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">

    <!-- Your Page Content Here -->
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">添加电站 <small>所属用户：{{$user->name}}</small></h3>
                </div>
                <!-- /.box-header -->
                <!-- form start -->
                <form class="form-horizontal" id="J-form" action="/admin/site/create-user-site" method="post">
                    <input name="user_id" type="hidden" value="{{$user->id}}">
                    <div class="box-body">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">电站名称</label>

                            <div class="col-sm-10">
                                <input name="name" type="text" class="form-control" placeholder="电站名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">地址</label>

                            <div class="col-sm-10">
                                <input name="address" type="text" class="form-control" placeholder="地址">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">坐标</label>

                            <div class="col-sm-10">
                                <input name="position" type="text" class="form-control" placeholder="坐标（经纬度坐标，暂时不填）">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">电站照片</label>

                            <div class="col-sm-10">
                                <div class="upload">
                                    <a href="javascript:;" class="btn btn-info btn-sm">上传照片</a>
                                    <input type="file" class="J-upload">
                                    <input id="J-img-hidden-input" type="hidden" name="img" value="">
                                </div>
                                <img src="" alt="" id="J-img-preview" style="display: none;">

                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">描述</label>

                            <div class="col-sm-10">
                                <textarea name="description" class="J-textarea" placeholder="Place some text here" style="width: 100%; height: 200px; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;"></textarea>
                            </div>
                        </div>

                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer">
                        <button type="submit" class="btn btn-info pull-right">添加</button>
                    </div>
                    <!-- /.box-footer -->
                </form>
            </div>

        </div>
    </div>

    <!-- /.box -->

</section>
<!-- /.content -->


@stop

@section('js')
    <script>

        $(function () {

            var uploader = simple.uploader({
                url: '/common/img-upload-upyun',
                params: {
                    tag: 'site-img'
                },
                connectionCount: 1
            });
            uploader.on('uploadsuccess', function (e, file, data) {
                if (data.status == 1) {
                    $('#J-img-preview').attr('src',data.data).show();
                    $('#J-img-hidden-input').val(data.data);
                } else {
                    alert(data.error_msg);
                }
            });
            $('.J-upload').on('change', function (e) {
                uploader.upload(this.files);
            });

            $(".J-textarea").wysihtml5();

            $('#J-form').ajaxForm({
                beforeSubmit: function () {
                    validator_info_clear($('#J-form'));
                },
                success: function (data) {
                    if (data.status == 1) {
                        alert('添加成功！');
                        window.location.href = '/admin/site/user-site?user_id={{$user->id}}';
                    } else {
                        alert(data.error_msg);
                    }
                },
                error: function (xhr) {
                    validator_info_show($('#J-form'), xhr);
                }
            });
        });


    </script>
@stop